<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 300px;
            background-color: pink ;
            box-sizing: border-box;
            padding: 30px;
            margin: 30px;
            box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
        }
    </style>
</head>

<body>
    <div></div>
    <label for="name">姓名</label>
    <input type="text" name="name" id="name" autofocus>
    <label for="password">密码</label>
    <input type="text" name="pwd" id="password">
    <script>
        var xhr = new XMLHttpRequest();
        var oStr = '';
        var str = {
            'username': 'admin',
            'password': '123456'
        }
        // postData = { "name1": "value1", "name2": "value2" };
        //这里需要将json数据转成post能够进行提交的字符串  name1=value1&name2=value2格式
        str = (function (value) {
            for (var key in value) {
                oStr += key + "=" + value[key] + "&";
            };
            return oStr;
        }(str))
        xhr.open('post', 'http://127.0.0.1:8888/api/private/v1/login', true);
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

        xhr.send(str);
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status == 200) {
                    console.log(xhr.response);
                }

            }
        }
    </script>
</body>

</html>